package com.ks.comment.service.impl;

import com.baomidou.mybatisplus.annotations.TableField;
import com.ks.comment.controller.dto.JournalResponse;
import com.ks.comment.controller.dto.ShareResponse;
import com.ks.comment.entity.ZpzShare;
import com.ks.comment.dao.ZpzShareMapper;
import com.ks.comment.service.IZpzShareService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ks.comment.service._ServiceBase;
import com.ks.core.util.ToolUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 信息转发日志表 服务实现类
 * </p>
 *
 * @author kingdee123
 * @since 2020-12-18
 */
@Service
public class ZpzShareServiceImpl extends _ServiceBase<ZpzShareMapper, ZpzShare> implements IZpzShareService {

    @Resource
    private ZpzShareMapper zpzShareMapper;

    @Override
    public int addShare(String token, int informationId, String type, String forwardName) {
        String userId = this.getUserId(token);
        if (ToolUtil.isNotEmpty(userId)) {
            ZpzShare zpzShare = new ZpzShare();
            zpzShare.setIforward(forwardName);
            zpzShare.setIuserId(Integer.valueOf(userId));
            zpzShare.setInformationId(informationId);
            zpzShare.setCType(type);
            Integer insert = zpzShareMapper.insert(zpzShare);
            if (insert > 0) {
                //TODO  发送MQ
                this.SendMQ(zpzShare);
                return insert;
            }
        }
        return 0;
    }

    @Override
    public Map<String, Object> getShareList(int informationId, String type, int pageNo, int pageSize) {
        Map<String, Object> map = new HashMap<>();
        List<ShareResponse> shareList = zpzShareMapper.getShareList(informationId, type, pageNo, pageSize);
        int shareCount = zpzShareMapper.getShareCount(informationId, type);
        map.put("list", shareList);
        map.put("count", shareCount);
        return map;
    }
}
